#include "Class.hpp"
#include "initClass.hpp"
#include <cstring>
#include <typeinfo>

Elements::Elements(string img, int X, int Y, int life,int damage){
    
    image = img;
    posX  = X;
    posY = Y;
    this->life = life;
    this->damage = damage;
}
string Elements::getImage(){
    return image;
}
int Elements::getPosX(){
    return posX;
}
int Elements::getPosY(){
    return posY;
}
int Elements::getLife(){
    return life;
}
int Elements::getDamage(){
    return damage;
}
void Elements::setImage(string img){
    image = img;
}
void Elements::setPosX(int X){
    posX  = X;
}
void Elements::setPosY(int Y){
    posY  = Y;
}
void Elements::setLife(int life){
    this->life = life;
}
void Elements::setDamage(int damage){
    this->damage = damage;
}

void Elements::showData(){
    cout    <<"Posicion en X: " << posX << endl
            <<"Posicion en Y: " << posY << endl                
            <<"Su vida es: " << life << endl
            <<"El daño es: " << damage << endl;    
}
Plane::Plane(int gunT, int gunL, string image, int posX, int posY, int life,int damage): Elements( image, posX, posY, life, damage){

    gunType = gunT;
    gunLevel = gunL;
}

int Plane::getGunType(){
    return gunType;
}

int Plane::getGunLevel(){
    return gunLevel;
}

void Plane::setGunType(int gunT){
    gunType = gunT;
}

void Plane::setGunLevel(int gunL){
    gunLevel = gunL;
}

void Plane::showData(){
    cout << "Datos del Avion" << endl
            <<"Nivel de arma: " <<gunLevel << endl
            <<"Posicion en X: " << posX << endl
            <<"Posicion en Y: " << posY << endl                
            <<"Su vida es: " << life << endl
            <<"El daño es: " << damage << endl<<endl;    
}

Items::Items(int gift, string image, int posX, int posY, int life, int damage): Elements( image, posX, posY, life, damage){
    this->gift = gift;
}
void Items::showData(){
    cout << "Datos del Item" << endl
	 <<"Tipo de Item: " <<gift << endl
         <<"Imagen es " << image << endl	
	 <<"Posicion en X: " << posX << endl
         <<"Posicion en Y: " << posY << endl                
         <<"Su vida es: " << life << endl
         <<"El daño es: " << damage << endl<<endl;
}

int Items::getGift(){
    return gift;
}

void Items::setGift(int gift){
    this->gift = gift;
}
Enemy::Enemy(int gun, int givenPoints, int journey, string image, int posX, int posY, int life,int damage):Elements(image, posX, posY, life, damage){
    
    this->gun = gun;
    this->givenPoints = givenPoints;
    this->journey = journey;
}

 int Enemy::getGun(){
     return gun;
 }
 int Enemy::getGivenPoints(){
     return givenPoints;  
 }
 
 int Enemy::getJourney(){
     return journey;
 }
 void Enemy::setGun (int gun){
        this->gun = gun;
 
 }
 
 void Enemy::setGivenPoints (int givenPoints){
        this->givenPoints = givenPoints;
 
 }

 void Enemy::setJourney (int journey){
        this->journey = journey;
 }

 void Enemy::showData(){
    cout << "Datos del Enemigo" << endl
	 <<"La arma es: " <<gun << endl
	 <<"Su trayectoria es: " << journey << endl	
         <<"Su puntaje es: " << givenPoints << endl
         <<"Posicion en X: " << posX << endl
         <<"Posicion en Y: " << posY << endl                
         <<"Su vida es: " << life << endl
         <<"El daño es: " << damage << endl<<endl;    
}
 
 Boss::Boss(int scdGun, int gun, int givenPoints, int journey, string image, int posX, int posY, int life,int damage): Enemy(gun, givenPoints, journey, image, posX, posY, life, damage){
     secondGun = scdGun;
 }
 
 int Boss::getSecondGun(){
     return secondGun;
 }
 void Boss:: setSecondGun (int scdGun){
      secondGun = scdGun;
 
 } 
 
 void Boss::showData(){
    cout << "Datos del Jefe" << endl
	 <<"La segunda arma es: " <<secondGun << endl
	 <<"La arma es: " <<gun << endl
	 <<"Su trayectoria es: " << journey << endl	
	 <<"Su puntaje es: " << givenPoints << endl
         <<"Posicion en X: " << posX << endl
         <<"Posicion en Y: " << posY << endl                
         <<"Su vida es: " << life << endl
          <<"El daño es: " << damage << endl<<endl;    
}
 
 World::World(){     
     count = 0; 
 }
 
 /*World::World(string backGround, int shape, int score, int totalLife){
     count = 0;
     this->backGround=backGround;
     this->shape=shape;
     this->score=score;
     this->totalLife=totalLife;
 };*/
 
 
 string World::getBackGround(){
     return backGround;
 }
 
 int World::getShape(){
     return shape;
 }
 
 int World::getScore(){
     return score;
 }
 
 int World::getTotalLife(){
     return totalLife;
 }
 
 void World::setBackGround(string backGround){
     this->backGround=backGround;
 }
 
 void World::setScore(int score){
     this->score=score;
 }
 void World::setShape(int shape){
     this->shape=shape;
 }
 
 void World::setTotalLife(int totalLife){
     this->totalLife=totalLife;
 }
 
 void World::addElements(Elements* e){
     if(count > 999) return;
     members[count++]= e;
 }
 
 Elements* World::foundElements(int life){
     int lif;
     for (int i=0; i<count; i++){
        if (typeid(*members[i]) == typeid(Enemy) ){
            lif = ((Enemy *)members[i])->getLife();
        }
        if (typeid(*members[i]) == typeid(Plane) ){
            lif = ((Plane *)members[i])->getLife();
        }
        if (typeid(*members[i]) == typeid(Boss) ){
            lif = ((Boss *)members[i])->getLife();
        }
        if (lif==life) {
            return members[i];
        }
    }
    return NULL;
 }
 

 void World::showData(){
   for (int i=0; i<count; i++){
        members[i]->showData();//polimorfismo
    } 
}
 
 void World::eliminateElements(int life){/*Modificado*/
 int lif;
 Elements* aux;
     for (int i=0; i<count; i++){
        if (typeid(*members[i]) == typeid(Enemy) ){
            lif = ((Enemy *)members[i])->getLife();
        }
        if (typeid(*members[i]) == typeid(Plane) ){
            lif = ((Plane *)members[i])->getLife();
        }
        if (typeid(*members[i]) == typeid(Boss) ){
            lif = ((Boss *)members[i])->getLife();
        }
        if (lif==life) {
            aux = members[i];
            members[i]= NULL;
            for(i;i<count;i++){
                int a = i+1;
                members[i]=members[a];
            }
            return;
        }
    }
 
 }

Player::Player(string name, int tScore){
    this->name = name;
    totalScore = tScore;
}
string Player::getName(){
    return name;
}
int Player::getTotalScore(){
    return totalScore;
}
void Player::setName(string name){
    this->name = name;
}
void Player::setTotalScore(int tScore){
    totalScore = tScore;
}

initPos::initPos(){
    maxX = 30;
    maxY = 10;
    
}
void initPos::fillPos(const char* fileName){
    ifstream f(fileName,ifstream::in);
         
    if (!f){
        cout << "fallo abriendo archivo"<< endl;
    }else{
        for (int j=0;j<maxY;j++){//maxY = 10
        for (int i=0;i<maxX;i++){//maxX= 30
           string aux;
           f >> aux;
           if(aux == "0") aux = " ";
               
           pos[i][j] = aux;
            
                      
        }  
        }   
    }
    f.close();
    
    //cout<<midat2;
}
void initPos::showPos(){
    ofstream myFile;
    myFile.open("img_map.txt",ofstream::out);    
    
    if(!myFile){
        cout << "Fallo"<<endl;        
    }else{
       for (int j=0;j<maxY;j++){//maxY = 10
            for (int i=0;i<maxX;i++){//maxX= 30
                myFile << pos[i][j];
                //myFile << " ";
        }
            myFile << endl;
       }
    }
       
    myFile.close();
}



